<?php
/**
* 企业职位管理
*/
class ComPositionControl extends PublicControl
{
	public $model = null;

	public function __init()
	{

		header('Content-Type:text/html;charset=utf-8');
		$this->model = K('ComPos');
	}
	public function send_pos()
	{
		// header('Content-Type:text/html;charset=utf-8');
		if(IS_POST){
			//定义模型
			$model = $this->model;
			//执行验证/数据添加
			if(!$model->create()) $this->error($model->error);
			// 执行添加方法
			if($model->add_data()){
				$this->success('发布成功', U('check_pos'));
			}else{
				$this->error('最多允许发布5个职位');
			}
		}
		//调用顶级城市
		$cityModel =  K('City');
		$cityModel->update_cache();
		$topCity = $cityModel->topCity;
		$this->assign('topCity', $topCity);
		// p($topCity);
		$PosCateModel = K('PosCate');
		$PosCateModel->update_cache();
		//调用顶级职位类别
		$topPos = $PosCateModel->topPos;

		// p($topPos);
		$this->assign('topPos', $topPos);
		// $this->assign('topPos1', $topPos['1']);
		
		$this->display();
	}

	public function check_pos()
	{
		$pos = $this->model->get_pos(session('uid'));
		if(IS_POST){
			//职位动作处理，包括排名，开始，暂停，删除
			$this->model->pos_action();
			$this->success('操作成功');
		}
		//处理分页
		$page = $pos['page'];
		//删除掉数组里面的分页，防止html页面循环出错
		unset($pos['page']);
		$this->assign('page',$page);

		//分配数据，相当于assign
		$this->pos = $pos;
		$this->display();
	}

	public function edit_pos()
	{
		$cpid = Q('get.cpid',0,'intval');
		if(IS_POST){
			if(!$this->model->create())$this->error($this->model->error);
			$this->model->pos_save($cpid);
			$this->success('操作成功',U('Index/index'));
		}
		#取出数据
		$data  = $this->model->get_id_pos($cpid);
		#取出城市数据
		$cityModel = K('City');
		$city = $cityModel->get_city($data['city_cityid']);
		#取出职位信息
		$posModel = K('PosCate');
		$pos = $posModel->get_pos_by_id($data['cate_posid']);
		$this->assign('data',$data);
		$this->assign('topCity',$cityModel->topCity);
		$this->assign('topPos',$posModel->topPos);
		$this->assign('city',$city);
		$this->assign('pos',$pos);
		$this->display();
	}
}
?>
